 const app = new Vue({
    el: '#login',
    data() {
      return {
        username: '',
        password: '',
      }
    },
    created() {
      this.checkLogin()
    },
    methods: {
      reset() {
        this.username = ''
        this.password = ''
      },
      async signin() {
        const { data: res } = await axios({
          method: 'post',
          url: '/login',
          data: {
            username: this.username,
            password: this.password,
          },
        })
        if (res.status == 401) return alert(res.message)
        const token = res.token
        localStorage.setItem('token', token)
        location.href = '/'
      },
      async checkLogin() {
        const token = localStorage.getItem('token')
        if (token) {
          try {
            const { data: res } = await axios({
              method: 'post',
              url: '/api/tokenVerify',
              data: {
                token: window.localStorage.getItem('token'),
              },
            })
            return (location.href = '/')
          } catch (error) {
            token: window.localStorage.removeItem('token'),
              console.log('用户过期了')
          }
        }
      },
    },
  })

